package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.model.SmsHomeBrand;
import com.jie.langlangmall.service.SmsHomeBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/25
 * @Email 3217998214@qq.com
 * @Description 首页品牌管理
 */
@RestController("/home/brand")
@Tag(name = "SmsHomeBrandController", description = "首页品牌管理")
@RequestMapping("/home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService homeBrandService;

    @Operation(summary = "分页查询推荐品牌")
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsHomeBrand>> list(@RequestParam(value = "brandName", required = false) String brandName,
                                                       @RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
                                                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<SmsHomeBrand> homeBrandList = homeBrandService.list(brandName, recommendStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(homeBrandList));

    }

    @Operation(summary = "添加首页推荐品牌")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody List<SmsHomeBrand> homeBrandList) {
        homeBrandService.create(homeBrandList);
        return CommonResult.success();
    }

    @Operation(summary = "修改推荐品牌排序")
    @PostMapping("/update/sort/{id}")
    public CommonResult<?> updateSort(@PathVariable Long id, Integer sort) {
        homeBrandService.updateSort(id, sort);
        return CommonResult.success();
    }

    @Operation(summary = "批量删除推荐品牌")
    @PostMapping("/delete")
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        homeBrandService.delete(ids);
        return CommonResult.success();
    }

    @Operation(summary = "批量修改推荐品牌状态")
    @PostMapping("/update/recommendStatus")
    public CommonResult<?> updateRecommendStatus(@RequestParam("ids") List<Long> ids, @RequestParam Integer recommendStatus) {
        homeBrandService.updateRecommendStatus(ids, recommendStatus);
        return CommonResult.success();
    }

}
